import xlrd
import pyecharts.options as opts
data=xlrd.open_workbook(r'C:\Users\chumenliuxiang\Desktop\实验室作业\第一问\第一问.xls','r')
sheet_num=data.nsheets
# print(sheet_num)
biao1=data.sheet_by_name('Sheet1')
scores=biao1.col_values(1)
scores=scores[1:]
# print(scores)
# print(st)

s0=s1=s2=s3=s4=s5=s6=s7=s8=s9=0
for i in scores:
    if i<=10:
        s0=s0+1
    elif i<=20:
        s1+=1
    elif i<=30:
        s2+=1
    elif i<=40:
        s3+=1
    elif i<=50:
        s4+=1
    elif i<=60:
        s5+=1
    elif i<=70:
        s6+=1
    elif i<=80:
        s7+=1
    elif i<=90:
        s8+=1
    elif i<=100:
        s9+=1
student2=[]
student2.append(s1)
student2.append(s2)
student2.append(s3)
student2.append(s4)
student2.append(s5)
student2.append(s6)
student2.append(s7)
student2.append(s8)
student2.append(s9)
# print(student2)
#————————————————————————————数据处理完成
from pyecharts import options as opts
from pyecharts.charts import Bar

(
    Bar()
    .add_xaxis(
        [
            "10~20",
            "20~30",
            "30~40",
            "40~50",
            "50~60",
            "60~70",
            "70~80",
            "80~90",
            "90~100"
        ]
    )
    .add_yaxis("scores",student2)
    .set_global_opts(
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)),
        title_opts=opts.TitleOpts(title="学习成绩直方图",pos_left='center',pos_bottom='1%'),
    )
    .render("第三问.html")
)